home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / GRAPHICS / GRAPHUTL / 1344.ZIP / CARTOG.ARC / CARTOG.DOC < prev    next >
Encoding:
Text File  |  1988-11-04  |  16.4 KB  |  336 lines

  1. Last updated: 11/04/88
  2.  
  3.                  CARTOG
  4.         A Cartography Program from BYTE Magazine
  5.     
  6.     This disk contains several versions of the program CARTOG.PAS
  7. described  in  "Mapping the World in Pascal" by Robert Miller and
  8. Francis Reddy (BYTE,  December 1987,  page 329). The program is a
  9. simple tutorial which allows you to view the properties of various
  10. map projections on a graphics screen.  The  code shows how many of  
  11. the more common projections are calculated,  but  is  neither  the 
  12. best nor the fastest means of doing so -- its purpose is the clear 
  13. illustration of how maps are computed.  To make  start-up  of  the 
  14. programs a little easier, we  have included batch files. See below.
  15.   
  16.                Files on This Disk
  17.     
  18.    CARTOG   DOC  This documentation
  19.    CARTOG   PAS  Source code from BYTE, December 1987
  20.    METAWNDO EXE  Auto-loading and terminating graphics driver
  21.    PRTSCRN  EXE  "                      "     screen dump
  22.    RUN      BAT  Use this if you have no math coprocessor 
  23.    CARTOG   COM
  24.    RUN87    BAT  Use this if you have a math coprocessor
  25.    CARTOG87 COM
  26.    WORLD    DAT  6,000-point coastline database
  27.  
  28.     If  you have no 80x87,  just type "RUN" at the DOS prompt; if
  29. you do  have  an  80x87  installed,  type "RUN87".  
  30.  
  31.                Getting  Started  
  32.  
  33.     The  MetaWindow  graphics  driver   allows us to support CGA,
  34. EGA,  AT&T,  and  Hercules-type graphics cards.   The driver will
  35. first  test  for  the  card on your system,  then report the card
  36. detected  above  the  CARTOG   menu.   You probably won't have to
  37. worry  about  it,  but  if  you  are  using  a  multi-mode  card,
  38. MetaWindow  may  not come to the correct conclusions!   Check the
  39. "Graphics:  "  line above the Menu -- if it does not match one of
  40. the  mode's  of your card,  or if CARTOG appears to run but draws
  41. nothing on the graphics screen,  you may need to modify the batch
  42. file  by  adding the appropriate command switch from those listed
  43. below. 
  44.  
  45. Switch Graphics Board                           Resolution
  46. -----------------------------------------------------------------
  47.  /A:1  AT&T Graphics Adaptor,                    640x400 2-color
  48.  /A:2  AT&T Display Enhancement Board (DEB),     640x200 16-color
  49.  /A:3  AT&T Display Enhancement Board (DEB),     640x400 16-color
  50.  /C:1  IBM Color Graphics Adaptor (CGA)          640x200 2-color
  51.  /E:1  IBM Enhanced Graphics Adaptor (EGA)       640x350 mono
  52.  /E:2  IBM Enhanced Graphics Adaptor (EGA)       320x200 16-color
  53.  /E:3  IBM Enhanced Graphics Adaptor (EGA)       640x200 16-color
  54.  /E:4  IBM Enhanced Graphics Adaptor (EGA, 128K) 640x350 16-color
  55.  /E:5  IBM PS/2 Video Graphics Array (VGA)       640x480 16-color
  56.  /E:6  IBM Enhanced Graphics Adaptor (EGA)       640x350 2-color
  57.  /E:7  IBM PS/2 MultiColor Graphics Array (MCGA) 640x480 2-color
  58.  /H    Hercules/AST Monochrome Graphics Adaptor, 720x348 mono
  59.  /O    Toshiba 3100,                             640x400 mono
  60.  /T:1  Tecmar Graphics-Master Adaptor,           720x352 mono
  61.  /T:3  Tecmar Graphics-Master Adaptor,           640x200 16-color
  62.  /T:4  Tecmar Graphics-Master Adaptor,           640x400 16-color
  63.  /U:1  Video-7 Vega Deluxe,                      640x480 16-color
  64.  /V:1  Everex Edge Adaptor,                      640x200 16-color
  65.  /V:2  Everex Edge Adaptor,                      640x400 4-color
  66.  
  67.     For example, the driver will identify the PS/2 video board as
  68. "IBM EGA,  640 x 350" rather than "IBM VGA,  640 x 480." Altering
  69. the  batch  file to read "Metawndo CARTOG /E:5" tells the program
  70. what hardware to draw to. Please note that the MetaWindow driver,
  71. although a terminate-and-stay-resident program, eliminates itself
  72. from  memory when you exit CARTOG.   An additional note:  Several
  73. users  have  reported  problems   with certain cards (notably the
  74. Paradise  EGA  card)  and the Metawndo driver.   While we cannnot
  75. solve  specific  hardawre  problems  (other  than  providing  the
  76. command  line  switches  above),  we  would  appreciate   problem
  77. reports  so  that we may pass them on to MetaGraphics,  makers of
  78. the  driver.   Also,  we  are readying a version of CARTOG in the
  79. latest  version  of  Turbo  Pascal,  which  includes    extensive
  80. graphics support. 
  81.     To make CARTOG more flexible,  you may specify a data file to
  82. read on the command line.   Otherwise,  CARTOG looks for the file
  83. WORLD.DAT.  
  84.  
  85.                         T H E  M A P S
  86.  
  87. The following briefly  describes  the types  of maps CARTOG draws.   
  88. For  more information,  see  the  BYTE  article  and  consult  any  
  89. of the references mentioned therein.
  90.  
  91.           
  92.               Map 1: The Mercator 
  93.  
  94.     o  Preserves shape but distorts area, especially
  95.        in polar regions;
  96.     o  Poles lie at infinity;
  97.     o  Meridians are straight, equally spaced lines;
  98.     o  Parallels are straight lines spaced unequally, closest
  99.        near Equator;
  100.     o  Meridians and parallels intersect at right angles.
  101.     
  102.     Quick.   Which  is  bigger:  Greenland  or South  America? If
  103. you're  not at all sure,  part of the blame rests with the Merca-
  104. tor  projection.   Greenland is only one-eighth the size of South
  105. America,  but  Mercator's  projection  makes it into a full-blown
  106. continent!   The  map  is   often   the   only    two-dimensional
  107. representation   of  the  Earth  many students see.   Its primary
  108. purpose  is  navigational.   A  ship  or plane following the same
  109. compass  course  will  travel  a  straight line when plotted on a
  110. Mercator  map.   Gerhardus  Mercator developed this projection in
  111. 1569  specifically  as  an   aid   to   navigation.    Mercator's
  112. projection  is  classed as a cylindrical,  and at first glance it
  113. looks  much   like   the   Equidistant  Cylindrical (Map 2 in the
  114. program's menu).  
  115.     But  look  again.   On  a  Mercator map,  the poles cannot be
  116. shown because they lie at infinity,  and the spacing between par-
  117. allels  increases  with increasing distance from the equator.   A
  118. region  at  the  60th  parallel  plots twice as large as the same
  119. area at the equator.  Moved to 80 degrees, that same area becomes
  120. 33 times larger than at the equator!   The Mercator is said to be
  121. conformal  --  it  maintains the shapes of small areas at the ex-
  122. pense of distorting sizes.   In contrast,  the Equidistant Cylin-
  123. drical preserves neither.
  124.  
  125.          Map  2:  The  Equidistant  Cylindrical
  126.  
  127.     o  Preserves neither shapes nor areas;
  128.     o  Poles shown as lines;
  129.     o  Meridians and parallels are equidistant
  130.        straight lines intersecting at right angles;
  131.     o  Easy to compute.
  132.  
  133.     Imagine  a  globe  tucked  inside a cylinder so that only the
  134. equator  touches  the  sides.   That's the basic idea behind this
  135. and  all  other  so-called  "cylindrical"  projections.    "Graph
  136. paper"  may  be  the  best way to describe the Equidistant Cylin-
  137. drical.   In  this   projection's   simplest  form the equator is
  138. chosen  to  be  the standard parallel,  called Phi1.   This means
  139. that  the  equator  is  the  latitude displayed true to scale and
  140. without  distortion.   If   meridians   and parallels are equally
  141. spaced,  the result is a grid of tiny squares twice as long as it
  142. is wide.  Experiment with different values of Phi1 and watch what
  143. happens to the map.
  144.     All  in  all,  the Equidistant Cylindrical is not a very good
  145. choice for displaying geographic data.  It preserves neither area
  146. nor  shape  and  is best used when distortions are less important
  147. than just getting the data on-screen as quickly as possible.
  148.      
  149.              Map 3: The Sinusoidal
  150.  
  151.     o  Equal area;
  152.     o  Central meridian is straight, all others sinusoidal 
  153.        curves;
  154.     o  Parallels equally spaced straight lines;
  155.     o  Easy to compute.
  156.  
  157.     The  Sinusoidal  projection  is more useful and only slightly
  158. more  complex.   Developed  in  the 16th century,  the Sinusoidal
  159. shows  areas   correctly   and   exhibits no distortion along the
  160. equator  and central meridian.   Distortion becomes pronounced at
  161. the outer meridians,  extreme near the poles.  Latitude lines are
  162. straight,  parallel,  and equally spaced. The central meridian is
  163. a straight line and crosses all parallels at right angles;  other
  164. meridians  form  curves,  their curvature increasing with greater
  165. distance  from  the  map's  center.   You'll  usually  see    the
  166. Sinusoidal  used for world maps,  often in an "interrupted" form.
  167. In  this  case  the world is broken into sections,  each with its
  168. own  central meridian.   Some atlases also use the Sinusoidal for
  169. South America, Africa, and the central Pacific.
  170.  
  171.                Map 4: The Hammer  
  172.  
  173.     o  Equal area;  
  174.     o  Equator and central meridian are striaght lines;
  175.     o  Curvature of meridians increase as distance from
  176.        central meridian increases;
  177.     o  Curvature of parallels increases with increasing
  178.        distance from the Equator.
  179.  
  180.     This  equal-area  projection  was  developed in the late 19th
  181. century  by  a   German   professor of surveying.   It looks more
  182. realistic  than  the  other equal-area projection discussed here,
  183. the  Sinusoidal,  but  this  realism  comes at a  price. Hammer's
  184. projection  has curved parallels and curved meridians,  a feature
  185. which makes it somewhat more difficult to construct.   Of course,
  186. it's a good choice for displaying global distributions because it
  187. shows the whole world at a glance. Climatic data, the movement of
  188. continents,  the distribution of astronomical objects -- all have
  189. been plotted on this projection in recent science journals.
  190.  
  191.             Map 5: The Orthographic
  192.  
  193.     o  Perspective projection from infinite distance (like
  194.        the view through a telescope);
  195.     o  Only one hemisphere can be shown at a time;
  196.     o  Great distortion along the edge of the visible 
  197.        hemisphere;
  198.     o  Azimuthal -- directions from map center to every other
  199.        point on the map are shown correctly;
  200.  
  201.     The problem in this projection is to determine whether or not
  202. each point is visible from the viewing location (central meridian
  203. and standard parallel) you choose. The Orthographic presents "the
  204. view  from  infinity,"  the Earth as seen from far away in space.
  205. The result is a map that looks very much like a globe.  It is the
  206. least  useful  map for making measurements because of the extreme
  207. distortion  near  its edges -- in fact,  the center of the map is
  208. the only point without distortion.   Unlike the other projections
  209. mentioned  here,  the Orthographic plots only one hemisphere on a
  210. single map. It is generally reserved for pictorial views, such as
  211. for index maps in an atlas.
  212.  
  213.            Scaling to a Graphics Board
  214.  
  215.     CARTOG.PAS scales these maps for CGA graphics.   To determine
  216. how  you  alter  the graphics constants for your specific system,
  217. you  must  first  examine   the  comment accompanying each of the
  218. mapping procedures.   In Procedure Sinusoidal,  for example,  the
  219. comment states:
  220.     
  221.     For R = 1: -Pi <= X <= Pi  and  -Pi/2 <= Y <= Pi/2. 
  222.     
  223.     This  is the key for calculating the proper R to fill a given
  224. graphics screen. R represents the radius of the scaled-down globe
  225. from  which  the map is developed -- it's the radius of the globe
  226. at the scale of the map.  A large-scale map,  such as a road map,
  227. uses  a  very large "model" globe;  a small-scale map,  such as a
  228. world map in an atlas, uses a small generating globe. This number
  229. depends on the map projection, the size of the sheet on which the
  230. map is being drawn, and the region being mapped. 
  231.     To scale the maps to a computer screen,  you need to know the
  232. values  returned  by  each   map   projection for a globe of unit
  233. radius.  You  also need to know the resolution of your screen and
  234. its aspect ratio -that is, the factor by which you need to divide
  235. the  X  coordinate  to   compensate for non-square pixels.  As an
  236. example, let's find the R for displaying a full Sinusoidal map on
  237. the CGA.  The map's total range is 2Pi in X, Pi in Y. The map's X
  238. axis  must fit within 640 pixels,  the Y axis must fit within 200
  239. pixels. For the CGA, the aspect ratio is 2.4. So for X:
  240.     
  241.      R = {( Screen  - Screen  ) / ( Map -  Map  )} / Aspect 
  242.         Xmax      Xmin       Xmax   Xmin
  243.  
  244.        = (640 / 2Pi) / 2.4
  245.  
  246.        = 42.4.
  247.  
  248. And for Y:
  249.  
  250.      R = {(Screen  - Screen)  /  (Map  - Map    )}
  251.           Ymax      Ymin        Ymax   Ymin
  252.  
  253.        = 200 / Pi
  254.  
  255.        = 63.6.
  256.  
  257.     The  smallest R controls,  so to fit a full Sinusoidal map on
  258. the  CGA  requires  an   R   of  42.4,  which we rounded to 40 in
  259. CARTOG.PAS.   Note  that  this  is also the correct value for the
  260. Mercator  and Equidistant Cylindrical projections.   As it turned
  261. out,  we  could  use  this  value for all the projections,  so we
  262. defined it as a constant.   In CARTOG,  however, we make each map
  263. fill  the  graphics   screen   by   adjusting R when you choose a
  264. projection.  To make the Hammer and Orthographic maps as large as
  265. possible  on your graphics screen,  you must go through the above
  266. process to find the right R.
  267.     If you don't know the aspect ratio of your system,  just plot
  268. the  Orthographic's  grid  and  plug   in values until it forms a
  269. circle.   Depending on your system, you may also need a different
  270. aspect  ratio  to get proper screen dumps from your printer.  The
  271. following  graphics  constants  work  with  most  common  display
  272. resolutions. 
  273.  
  274. EGA:                   Hercules:           VGA: 
  275. CONST XCENTER = 320;      XCENTER = 360;      XCENTER = 320; 
  276.       YCENTER = 174;      YCENTER = 174;      YCENTER = 240;
  277.       ASPECT  = 1.37;     ASPECT  = 1.5;      ASPECT  =   1;
  278.       R       = 70;       R       = 70;       R       =  70;
  279.  
  280.                 The  Data
  281.  
  282.     In  programs  like CARTOG,  which require large quantities of
  283. data,  the file's format should be chosen carefully.  You want to
  284. take  care to keep the size of the file small and facilitate fast
  285. input.   We  decided  against  using an ASCII text file since the
  286. conversion  to binary numbers for the calculations would take too
  287. long;  a  floating-point number format would have required a file
  288. several times larger than the present one.   The non-8087 version
  289. of  Turbo  Pascal uses a floating-point format different from the
  290. 8087 version,  further making portability a problem. 
  291.     We  decided  to  store   the program's longitude and latitude
  292. coordinates  as integers.   We chose to use a Pascal binary file.
  293. The  first  two  bytes of each record is a two-letter ASCII code:
  294. 'LS'  means  to draw line strings,  beginning with the data point
  295. in  this record,  and connect  all subsequent points with records
  296. containing  an 'S' code.   (This was done for reasons of downward
  297. compatibility  to  other software and we have not yet bothered to
  298. change  it.   Future  versions  of CARTOG will reduce this to one
  299. byte.)  Each  record   contains   one  data point consisting of a
  300. longitude/latitude   pair.   The   longitudes  and  latitudes are
  301. stored  as   a   (16   bit)  integer representing hundredths of a
  302. degree.   Coordinates  south  of  the   equator and those west of
  303. Greenwich  are  considered  negative.   This  scheme  produces  a
  304. relatively  compact  data  file  giving an adequate resolution of
  305. data points for this purpose.   The WORLD.DAT file distributed by
  306. BYTE  was  compiled  by  the authors from two government-produced
  307. world maps.   For Antarctica,  we used a polar view from the U.S.
  308. Geological  Survey's  1:40,000,000 "World Outline Map";  all else
  309. was  taken  from  the Defense Mapping Agency's "The World," which
  310. is  also available through the USGS.   The resulting binary file,
  311. which consists of about 6,000 latitude/longitude pairs,  provides
  312. a  nice  low-resolution view of the world.   
  313.     We  have  subsequently   obtained a high-resolution coastline
  314. database  from  the   Goddard   Space Flight Center in Greenbelt,
  315. Maryland.   The  smaller  file  contains  about  15,000    points
  316. (appropriate  to  a  scale of about 1:8,000,000);  the larger one
  317. holds about 95,000 points (1:6,000,000),  including international
  318. boundaries  and  state  boundaries  within  the  U.S.  For a nom-
  319. inal copying/handling charge,  we will be happy to send you these 
  320. data.  All data are derived from WORLD DATABANK 1, which was ori-
  321. ginally developed in the 1960s by the U.S. government.
  322.     For more information,  feel free to contact me at the address 
  323. below: 
  324.  
  325. Francis Reddy
  326. c/o Parnau Graphics, Inc.
  327. 2857 S. 160th St.
  328. New Berlin, WI  53151
  329.  
  330. Or call:
  331.  
  332. CompuServe (E-MAIL to Jeff Parnau)        : 71555,126
  333. Exec-PC BBS                               : 414-964-5160
  334. TOPAZ BBS (E-MAIL to SYSOP or Frank Reddy): 414-784-6458 
  335.  
  336.                    - - - - - - E N D - - - - - - -